const path = require('path')
const fs = require('fs')
const TerserPlugin = require('terser-webpack-plugin')

/**
 * 拼接相对于当前目录的下 文件的相对路径
 * @param dir 目录
 * @return {string}
 */
function resolove(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  lintOnSave: true,
	productionSourceMap: false,
  css: {
  },
  devServer: {
    port: 9000,
    proxy: 'http://127.0.0.1:9999/'
  },
  chainWebpack: config => {
    // 移除 prefetch 插件
    config.plugins.delete('prefetch');
    config.resolve.alias
      .set('IMG', resolove('static/image'))
      .set('PAGES', resolove('pages'))
      .set('COMPONENTS', resolove('components'))
      .set('UTIL', resolove('utils'))
      .set('API', resolove('api'));
  },
  configureWebpack: {
    plugins: [],
    optimization: {
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            warnings: false,
             compress: {
              drop_console: true,
              drop_debugger: true,
              pure_funcs: ['console.log']
            }
          }
        })
      ]
    }
  }
};
